package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.api.dao.SearchMapper;
import com.qf.lanzhou.shop.api.service.SearchService;
import com.qf.lanzhou.shop.pojo.entity.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @author 是柠檬甜
 * @date 2021/1/12 9:13
 */
@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private SearchMapper searchMapper;

    @Override
    public HashSet<Goods> search(String searchKey) {
        String[] split = searchKey.split("/");
        Goods goods;
        HashSet<Goods> search=new HashSet<>();
        HashSet<Goods> select;
        for (int i = 0; i < split.length; i++) {
            goods = new Goods();
            goods.setName(split[i]);
            goods.setSummary(split[i]);
            goods.setControlType(split[i]);
            goods.setMaterial(split[i]);
            goods.setShopName(split[i]);
            goods.setAppearance(split[i]);
            goods.setFunction(split[i]);
            goods.setCategory(split[i]);
            select = searchMapper.select(goods);
            Iterator<Goods> iterator = select.iterator();
            while (iterator.hasNext()) {
                search.add(iterator.next());
            }
        }
        System.out.println("是柠檬甜lll"+search);
        if (search.size()==0){
            throw new RuntimeException("未找到该商品，请重新选择关键字");
        }
        return search;
    }
}
